<?php

namespace application\model;

use application\entity\db\Image;
use application\entity\enu\ImageType;
use application\model\BaseModel;
use core\entity\Criteria;
use core\entity\Query;

class ImageModel extends BaseModel {

    public function __construct() {
        parent::__construct(Image::class);
    }

    /**
     * 
     * @param type $targetId
     * @param type $type
     * @return type
     */
    public function get($targetId, $type = ImageType::_DEFAULT) {
        $cri = new Criteria();
        $cri->andKey("target")->is($targetId);
        $cri->andKey("type")->is($type);
        $query = new Query($cri);
        return $this->ifind($query);
    }

    /**
     * 
     * @param type $targetIds
     * @param type $type
     * @return type
     */
    public function getByTargetIds($targetIds = [], $type = ImageType::_DEFAULT) {
        if (!is_array($targetIds)) {
            $targetIds = [];
        }
        $cri = new Criteria();
        $cri->andKey("target")->in($targetIds);
        $cri->andKey("type")->is($type);
        $query = new Query($cri);
        return $this->ifind($query);
    }

}
